export function getCharNumInString(str:string, singleChar:string) : number{
    let regStr:string = '\\'  + singleChar
    let reg:RegExp  = new RegExp(regStr,"ig")
    let transStr:string = str.replace(reg,"")
    return str.length-transStr.length;
}

export const flattenDeepByKey = (tree, key) => {
    if (!Array.isArray(tree) || tree.length === 0) return tree;
    const convert = (con, item) => {
        con.push(item);
        if (item[key] && item[key].length > 0)
            item[key].reduce(convert, con);
        return con;
    }
    return tree.reduce(convert, [])
}

export const noLengthAttrArrayLikeToArray = (noLengthAttrArrayLike:any) => {
    let len = Object.keys(noLengthAttrArrayLike).length
    noLengthAttrArrayLike.length = len
    return [].slice.call(noLengthAttrArrayLike)
}